﻿using System;
using System.Data;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Modules.DVDZone.Components;

namespace ASPNETVN.PORTAL.Modules.DVDZone.Controls
{
    public partial class Item : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                DataView dv = new DataView();
                if (Request.QueryString["CategoryID"] != null)
                {
                    // Begin build page link.
                    int categoryID = Convert.ToInt32(Request.QueryString["CategoryID"]);
                    PageLink pagelink = (PageLink)this.ParentControl.FindControl("MainPageLink");
                    Category category = Category.Load(categoryID);
                    Category parentCategory = Category.Load(category.ParentID);

                    pagelink.AddLink(parentCategory.Title, "#");
                    string url = ResolveClientUrl(HttpUrlBuilder.BuildUrl(this.ModuleID, 0, ModulePages.Item, "categoryid={0}", category.ID));
                    
                    pagelink.AddLink(category.Title, url);
                    // End build page link.

                    dv = Components.Item.SelectBy_CategoryID(Int32.Parse(Request.QueryString["categoryid"])).Tables[0].DefaultView;
                    dlItem.DataSource = dv;
                    dv.Sort = "CreatedDate DESC";
                }
                else
                {
                    //dv = Components.Item.SelectBy_ModuleID(this.ModuleID).Tables[0].DefaultView;
                    //dlItem.DataSource = dv;
                }

                dlItem.DataBind();

                
            }
        }
    }
}